home *** CD-ROM | disk | FTP | other *** search
Wrap
package bugbug; import com.siemens.mp.game.Light; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Hashtable; import java.util.Vector; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.List; import javax.microedition.lcdui.TextBox; import javax.microedition.midlet.MIDlet; import javax.microedition.rms.RecordStore; import javax.microedition.rms.RecordStoreException; public class BugBug extends MIDlet implements CommandListener { static final String EXIT_COMMAND_LABEL = "Exit"; static final String START_COMMAND_LABEL = "Restart"; static final String OK_COMMAND_LABEL = "OK"; Display display; YopparaiCanvas canvas; Thread updateThread; int mode = 0; Command exitCommand; TextBox tbox; Vector testVector; List ranker; private String ConstantValue; private String country; // $FF: renamed from: I long private long field_0; // $FF: renamed from: J int private static int field_1 = 100; Vector ranking; public BugBug() { Light.setLightOn(); this.canvas = new YopparaiCanvas(this); this.display = Display.getDisplay(this); this.exitCommand = new Command("Exit", 1, 0); } protected void destroyApp(boolean var1) { this.display.setCurrent((Displayable)null); ((MIDlet)this).notifyDestroyed(); } protected void pauseApp() { ((MIDlet)this).notifyPaused(); } protected void startApp() { this.game(); long var1 = System.currentTimeMillis() / 1000L; int var3 = Rand.rand(); String var4 = var1 + "." + var3; String var5 = "http://s.si.klab.org/s/s?t=1&v=1&q=" + String.valueOf(this.getAccessSequence()) + "&id=" + var4 + "&c=0&player=nobody&country=somewhere&score=0"; this.field_0 = 0L; } public void inputData() { switch (this.mode) { case 1: this.tbox = new TextBox("your name", "", 256, 0); break; case 2: this.tbox = new TextBox("your country", "", 12, 0); case 3: default: break; case 4: this.tbox = new TextBox("Please!", "Please enter your name!", 256, 0); break; case 5: this.tbox = new TextBox("Please!", "Please enter your country!", 256, 0); } this.tbox.setCommandListener(this); this.display.setCurrent(this.tbox); } public void game() { Command var1 = new Command("Restart", 1, 0); this.canvas.addCommand(var1); this.canvas.addCommand(this.exitCommand); this.canvas.setCommandListener(this); this.display.setCurrent(this.canvas); this.updateThread = new Thread(this.canvas); this.updateThread.start(); } public void commandAction(Command var1, Displayable var2) { String var3 = var1.getLabel(); String var4; if (this.tbox == null) { var4 = ""; } else { var4 = this.tbox.getString().trim(); } switch (this.mode) { case 0: if (var3 == "Exit") { this.display.setCurrent((Displayable)null); this.updateThread = null; this.canvas = null; this.destroyApp(true); } else if (var3 == "Restart") { this.canvas.init(); } break; case 1: if (var4.length() == 0) { this.mode = 4; this.inputData(); } else { this.ConstantValue = this.tbox.getString().trim(); this.mode = 2; this.inputData(); } break; case 2: if (var4.length() == 0) { this.mode = 5; this.inputData(); } else { this.country = this.tbox.getString().trim(); this.mode = 0; this.tbox = null; System.gc(); this.display.setCurrent(this.canvas); } break; case 3: this.mode = 0; this.display.setCurrent(this.canvas); this.canvas.init(); break; case 4: this.mode = 1; this.inputData(); break; case 5: this.mode = 2; this.inputData(); } } public void setMode(int var1) { this.mode = var1; } public String getPlayerName() { return this.ConstantValue; } public String getCountry() { return this.country; } public void checkInetHighscore() { long var1 = System.currentTimeMillis() / 1000L; int var3 = Rand.rand(); String var4 = var1 + "." + var3; (new StringBuffer()).append("http://s.si.klab.org/s/s?t=1&v=1&q=").append(String.valueOf(this.getAccessSequence())).append("&id=").append(String.valueOf(var4)).append("&c=0&player=").append(this.ConstantValue).append("&country=").append(this.country).append("&score=").append(this.field_0).toString(); this.mode = 3; if (field_1 > 0 && field_1 <= 10) { this.display.setCurrent(this.ranker); } else if (field_1 > 10 && field_1 <= 100) { TextBox var7 = new TextBox("Internet Ranking", "Your are the " + field_1 + "th.", 256, 0); ((Displayable)var7).setCommandListener(this); this.display.setCurrent(var7); } else if (field_1 == 0) { TextBox var6 = new TextBox("Internet Ranking", "Your are not in TOP100", 256, 0); ((Displayable)var6).setCommandListener(this); this.display.setCurrent(var6); } } public void showInetHighscore() { if (this.ranker == null) { long var1 = System.currentTimeMillis() / 1000L; int var3 = Rand.rand(); String var4 = var1 + "." + var3; String var5 = "http://s.si.klab.org/s/s?t=1&v=1&q=" + String.valueOf(this.getAccessSequence()) + "&id=" + var4 + "&c=0&player=nobody&country=somewhere&score=0"; } this.mode = 3; this.display.setCurrent(this.ranker); } public void getRanking(String var1) { try { this.getViaHttpConnection(var1); } catch (Exception var4) { } this.ranker = new List("Internet Ranking", 3); this.ranker.setCommandListener(this); for(int var2 = 0; var2 < this.ranking.size(); ++var2) { Hashtable var3 = (Hashtable)this.ranking.elementAt(var2); this.ranker.append(var2 + 1 + ": " + (String)var3.get("name") + " " + (String)var3.get("country") + " " + (Integer)var3.get("score"), (Image)null); } } public long getAccessSequence() { long var1 = -1L; try { RecordStore var3 = RecordStore.openRecordStore("A", true); if (var3.getNumRecords() > 0) { byte[] var4 = var3.getRecord(1); ByteArrayInputStream var5 = new ByteArrayInputStream(var4); DataInputStream var6 = new DataInputStream(var5); var1 = var6.readLong(); var6.close(); var5.close(); } else { var1 = -1L; } var3.closeRecordStore(); } catch (RecordStoreException var10) { System.out.println(var10); } catch (IllegalStateException var11) { System.out.println(var11); } catch (IOException var12) { System.out.println(var12); } ++var1; try { RecordStore var14 = RecordStore.openRecordStore("A", true); ByteArrayOutputStream var15 = new ByteArrayOutputStream(); DataOutputStream var16 = new DataOutputStream(var15); var16.writeLong(var1); byte[] var17 = var15.toByteArray(); if (var14.getNumRecords() == 0) { var14.addRecord(var17, 0, var17.length); } else { var14.setRecord(1, var17, 0, var17.length); } var16.close(); var15.close(); var14.closeRecordStore(); } catch (RecordStoreException var7) { System.out.println(var7); } catch (IllegalStateException var8) { System.out.println(var8); } catch (IOException var9) { System.out.println(var9); } return var1; } public void saveHighscore() { try { RecordStore var1 = RecordStore.openRecordStore("A", true); ByteArrayOutputStream var2 = new ByteArrayOutputStream(); DataOutputStream var3 = new DataOutputStream(var2); var3.writeLong(this.field_0); byte[] var4 = var2.toByteArray(); if (var1.getNumRecords() == 1) { var1.addRecord(var4, 0, var4.length); } else { var1.setRecord(2, var4, 0, var4.length); } var3.close(); var2.close(); var1.closeRecordStore(); } catch (RecordStoreException var5) { } catch (IllegalStateException var6) { } catch (IOException var7) { } } public void setLocalHighscore(int var1) { this.field_0 = (long)var1; } public long getLocalHighscore() { try { RecordStore var1 = RecordStore.openRecordStore("A", false); if (var1.getNumRecords() > 1) { byte[] var2 = var1.getRecord(2); ByteArrayInputStream var3 = new ByteArrayInputStream(var2); DataInputStream var4 = new DataInputStream(var3); this.field_0 = var4.readLong(); var4.close(); var3.close(); } else { this.field_0 = 0L; } var1.closeRecordStore(); } catch (RecordStoreException var5) { } catch (IllegalStateException var6) { } catch (IOException var7) { } return this.field_0; } public void getViaHttpConnection(String var1) throws IOException { HttpConnection var2 = null; InputStream var3 = null; this.ranking = new Vector(10); try { var2 = (HttpConnection)Connector.open(var1); var3 = var2.openInputStream(); String var4 = var2.getType(); int var5 = (int)var2.getLength(); byte[] var6 = new byte[var5]; var3.read(var6); ByteArrayInputStream var7 = new ByteArrayInputStream(var6); DataInputStream var8 = new DataInputStream(var7); if (var5 > 0) { short var9 = var8.readShort(); int var10 = var8.readByte() & 255; field_1 = var8.readByte() & 255; for(int var11 = 0; var11 < 10; ++var11) { int var12 = var8.readByte() & 255; int var13 = var8.readByte() & 255; byte[] var14 = new byte[var12]; var8.read(var14, 0, var12); byte[] var15 = new byte[var13]; var8.read(var15, 0, var13); int var16 = var8.readInt(); Hashtable var17 = new Hashtable(); var17.put("score", new Integer(var16)); var17.put("name", new String(var14)); var17.put("country", new String(var15)); this.ranking.addElement(var17); } } } finally { if (var3 != null) { var3.close(); } if (var2 != null) { var2.close(); } } } }